﻿using System.Collections.Generic;

namespace Cms.Domain.Comparers
{
    public class ContentComparer : IComparer<Content>
    {
        private readonly ContentSortMode _mode;
        private readonly SortDirection _sortDirection;

        public ContentComparer(SortDirection sortDirection, ContentSortMode mode)
        {
            _sortDirection = sortDirection;
            _mode = mode;
        }

        #region IComparer<Content> Members

        public int Compare(Content x, Content y)
        {
            int result = 0;
            switch (_mode)
            {
                case ContentSortMode.SortKey:
                    result = string.Compare(x.SortKey, y.SortKey);
                    break;
            }
            return _sortDirection == SortDirection.Ascending ? result : result * -1;
        }

        #endregion
    }
}